package com.juyu.miliao.api.controller;

import java.util.List;
import java.util.concurrent.CompletionException;

import javax.annotation.Resource;

import com.juyu.miliao.common.exception.ConsumeRuntimeException;
import org.springframework.security.core.Authentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.juyu.miliao.api.domain.Report;
import com.juyu.miliao.api.domain.UserReport;
import com.juyu.miliao.api.service.ReportService;
import com.juyu.miliao.api.validator.ReportCheck;
import com.juyu.miliao.common.domain.Subject;
import com.juyu.miliao.common.exception.IllegalParamException;

/**
 * 举报
 * 
 * @author wbf
 */
@RestController
@RequestMapping("/report")
public class ReportController {
	@Resource
	ReportService reportService;

	/**
	 * 获取举报信息
	 * 
	 * @return
	 */
	@GetMapping()
	public List<Report> getReportAll() {
		return reportService.getReportAll();
	}

	/**
	 * 举报用户
	 * 1.5.1新增举报人和被举报人是否为主播字段
	 */
	@PostMapping
	public void insertReportUser(Authentication token, @Validated(ReportCheck.class) UserReport entity) {
		Subject subject = (Subject) token.getPrincipal();
		if (subject.getId() != entity.getReportUserId())
			throw new IllegalParamException("用户id错误");
		reportService.insertReportUser(entity);
	}
}
